package com.usooft.metaTalent.db.wx.form;

import com.usooft.framework.core.query.Sort;
import com.usooft.framework.web.form.ListForm;
import com.usooft.metaTalent.core.wx.query.WxOpenUserQuery;
import java.lang.Long;
import java.lang.Override;
import java.lang.String;
import java.time.LocalDateTime;
import lombok.Setter;

@Setter
public class WxOpenUserListForm extends ListForm<WxOpenUserQuery> {
    private Long idIs;

    private Long[] idIn;

    private LocalDateTime createdDateOnOrBefore;

    private LocalDateTime createdDateOnOrAfter;

    private String openIdIs;

    private String unionIdIs;

    private Long userIdIs;

    @Override
    public WxOpenUserQuery buildQuery() {
        return WxOpenUserQuery.builder()
                                .filter(buildFilter())
                                .sorts(buildSorts())
                                .limit(getLimit())
                                .build();
    }

    private WxOpenUserQuery.Filter buildFilter() {
        return WxOpenUserQuery.Filter.builder()
                .idIs(idIs)
                .idIn(idIn)
                .createdDateOnOrBefore(createdDateOnOrBefore)
                .createdDateOnOrAfter(createdDateOnOrAfter)
                .openIdIs(openIdIs)
                .unionIdIs(unionIdIs)
                .userIdIs(userIdIs)
                .build();
    }

    private WxOpenUserQuery.Sorts buildSorts() {
        WxOpenUserQuery.Sorts.Builder builder = WxOpenUserQuery.Sorts.builder();
        for (String sortItem : getSortItems()) {
            Sort.Order order = getSortOrder(sortItem);
            switch (sortItem) {
                case "-id", "id" -> builder.id(order);
            }
        }
        return builder.build();
    }
}
